﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Configuration;
using System.Security.Cryptography;

namespace SocialIn.Biz.Utils
{
    public static class SecurityUtils
    {
        public static string Base64Encode(string str, System.Text.Encoding enc)
        {
            byte[] arr = enc.GetBytes(str);
            return Convert.ToBase64String(arr);
        }

        public static string Base64Decode(string str, System.Text.Encoding enc)
        {
            byte[] arr = Convert.FromBase64String(str);
            return enc.GetString(arr);
        }

        ///// <summary>
        ///// 입력문자열을 암호화하여 반환합니다.
        ///// </summary>
        ///// <param name="toEncrypt">대상문자열</param>
        ///// <returns>암호화문자열</returns>
        //public static string Encrypt(string toEncrypt)
        //{
        //    byte[] toEncryptArray = UTF8Encoding.UTF8.GetBytes(toEncrypt);

        //    SHA1CryptoServiceProvider SHA1 = new SHA1CryptoServiceProvider();
        //    byte[] hashValue = SHA1.ComputeHash(UTF8Encoding.UTF8.GetBytes(toEncrypt));
        //    StringBuilder sb = new StringBuilder();
        //    for (int i = 0; i < hashValue.Length; i++)
        //    {
        //        sb.Append(hashValue[i].ToString("X2"));
        //    }

        //    return sb.ToString();
        //}

        public static string Encrypt(string toEncrypt, string passwordFormat)
        {
            return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(toEncrypt, passwordFormat);
        }

    }
}